package com.atguigu.binaryTree;

import java.util.ArrayList;
import java.util.List;

public class IsBST2 {
    public static boolean isBst(TreeNode root){
        if(root==null) return true;
        List<TreeNode> list=new ArrayList<>();
        process(root,list);
        //判断list是否是升序
        for(int i=0;i<list.size()-1;i++){
            if(list.get(i+1).val<=list.get(i).val){
                return false;
            }
        }
        return true;
    }
    public static void process(TreeNode root,List<TreeNode> list){
        if(root==null) return;
        process(root.left,list);
        list.add(root);
        process(root.right,list);
    }
}
